home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0886.arc
/
SCHEME1.LTG
< prev
next >
Wrap
Text File
|
1986-06-24
|
1KB
|
23 lines
Listing 1
;;; Pattern: a pattern matcher in LISP
;;╗ (ModifieΣ froφ Commoε LIS╨ t∩ SCHEM┼ froφ "AI Eye,"
;;; COMPUTER LANGUAGE, Jan. & Mar. 1986)
;;;
;;; Test by entering: (match '(Now) '(and then)),
;;; which should return () and
;;; (match '(This is mine) '(This is mine)),
;;; which should return #!TRUE.
(DEFINE MATCH (LAMBDA (P E)
(COND ((OR (EQUAL? P E) ;Identical things match
(MEMBER P '(? *))) T) ;? and * match anything
((OR (ATOM? P) (ATOM? E)) NIL) ;No match now if not both list
((EQUAL? (CAR P) '*) ;If pattern starts with *, we
(OR (MATCH (CDR P) (CDR E)) ; match if both tails match or
(MATCH (CDR P) E)
(T (AND (MATCH (CAR P) (CAR E)) ;Else we match if heads match
(MATCH (CDR P) (CDR E)))))) ; and tails match